package com.jianyun.jyzs.utils;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.jianyun.jyzs.R;


/**
 * Created by liml on 17/5/15.
 */

public class FullDialogLoading extends Dialog {
    private Context context = null;
    private static FullDialogLoading fullDialog = null;
    private static ImageView img;

    public FullDialogLoading(Context context){
        super(context);
        this.context = context;
    }

    public FullDialogLoading(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }

    public static FullDialogLoading createDialog(Context context){
        fullDialog = new FullDialogLoading(context, R.style.fullDialog);
        fullDialog.setContentView(R.layout.dialog_loading);
        img = (ImageView)fullDialog.findViewById(R.id.loadingImageView);
        fullDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        return fullDialog;
    }

    /**
     *
     * setMessage 提示内容
     * @param strMessage
     * @return
     *
     */
    public FullDialogLoading setMessage(String strMessage){
        TextView tvMsg = (TextView)fullDialog.findViewById(R.id.id_tv_loadingmsg);
        if (tvMsg != null){
            tvMsg.setText(strMessage);
        }
        return fullDialog;
    }

    @Override
    public void show() {
        if(img != null){
            // 加载动画，动画用户使img图片不停的旋转
            Animation animation = AnimationUtils.loadAnimation(context, R.anim.dialog_load_animation);
            img.startAnimation(animation);// 显示动画
        }
        super.show();
    }

}
